package cz.af.portletExams.exapando;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.User;
import com.liferay.portlet.expando.service.ExpandoValueServiceUtil;
import cz.af.portletExams.util.AFPortletUtil;
import org.apache.log4j.Logger;

public class ExamsExpandoUtil {

    private static final Logger log = Logger.getLogger(ExamsExpandoUtil.class);

    public static String getUsernameForUser(long userId) {
        try {
            return (String) ExpandoValueServiceUtil.getData(AFPortletUtil.getCurrentCompany().getCompanyId(),
                    User.class.getName(), ExpandoApplicator.EXAPNDO_EXAM_USER, ExpandoApplicator.KOS_USERNAME, userId);
        } catch (PortalException e) {
            log.error(e);
        } catch (SystemException e) {
            log.error(e);
        }
        return "";
    }

    public static void setUsernameForUser(long userId, String username) {
        try {
            ExpandoValueServiceUtil.addValue(AFPortletUtil.getCurrentCompany().getCompanyId(), User.class.getName(), ExpandoApplicator.EXAPNDO_EXAM_USER,
                    ExpandoApplicator.KOS_USERNAME, userId, username);
        } catch (PortalException e) {
            log.error(e);
        } catch (SystemException e) {
            log.error(e);
        }
    }


}
